package com.ky.pro.java.nio.http.server.router;

import java.net.InetSocketAddress;
import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.Map;

/**
 * @ClassName ServiceRegistrar
 * @Description 简易的服务注册管理
 * @Date 2021/11/20 17:12
 * @Author kevin
 **/
public class ServiceRegistrar {

    Map<String, LinkedHashSet<InetSocketAddress>> serviceUrlMap = new HashMap<>();

    public void registerService(String serviceName, InetSocketAddress serviceAddress) {
        LinkedHashSet<InetSocketAddress> addresses = serviceUrlMap.get(serviceName);
        if (addresses == null) {
            addresses = new LinkedHashSet<>();
        }
        addresses.add(serviceAddress);
        serviceUrlMap.put(serviceName, addresses);
    }

    public LinkedHashSet<InetSocketAddress> getAddressSet(String serviceName) {
        return serviceUrlMap.get(serviceName);
    }

}
